//
//  SCTabBarViewController.swift
//  weibo
//
//  Created by 阿城 on 15/12/5.
//  Copyright © 2015年 阿城. All rights reserved.
//

import UIKit
import SVProgressHUD

class SCTabBarViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        setValue(SCTabBar(), forKey: "tabBar")
        
        let bar = tabBar as! SCTabBar
        
        bar.composeClick = {
        
            self.composeClick()
            
        }
        
        
//        tabBar.backgroundColor = UIColor.whiteColor()
//        printLog(tabBar )
//        tabBar.backgroundColor = UIColor.grayColor()
        view.backgroundColor = UIColor.whiteColor()
        addChildViewController(SCHomeViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(SCMessageViewController(), title: "信息", imageName: "tabbar_message_center")
        addChildViewController(SCDiscoverViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(SCProfileViewController(), title: "自己", imageName: "tabbar_profile")
        
    }
    
    
    
    func addChildViewController(childController: UIViewController, title: String, imageName: String) {
        
        tabBar.tintColor = UIColor.orangeColor()
//        let tabbar1 = UITabBar.appearance()
//        tabbar1.tintColor = UIColor.orangeColor()
        
        childController.tabBarItem = SCTabBarItem()
        childController.title = title
//        childController.tabBarItem.title = "safdsafdsa"
        childController.tabBarItem.image = UIImage(named: imageName)
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        

//        childController.tabBarItem.setTitleTextAttributes([ NSForegroundColorAttributeName: UIColor.redColor()], forState: UIControlState.Selected)
        
        addChildViewController(UINavigationController(rootViewController: childController))
    }
    
    
    @objc private func composeClick(){
//        printLog("composeClick")
        
        if !SCUserInfoViewModel.shareInfoViewModel.isLogOn{
           SVProgressHUD.showInfoWithStatus("请先登录", maskType: SVProgressHUDMaskType.Black)
            return
        }
        
        let composeView = SCComposeView()
        
        composeView.show(self)
        
    }

    
}
